<div class="subhead ">
  <div class="container mx-auto">
    <h5>~/admin/accounts</h5>
    <div class="log-settings">
      <%= render LogflareWeb.AdminSharedView, "nav_links.html", conn: @conn %>
    </div>
  </div>
</div>
<div class="content dashboard container mx-auto parent">
  <div class="side">
    <div class="dropdown">
      <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown"
        aria-haspopup="true" aria-expanded="false">
        Sort by: <%= @conn.params["sort_by"] %>
      </button>
      <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
        <%= for option <- @sort_options do %>
        <%= link option, to: Routes.admin_path(@conn, :accounts, sort_by: option), class: "dropdown-item" %>
        <% end %>
      </div>
    </div>
    <%= form_for @conn, Routes.admin_path(@conn, :accounts), [method: :get], fn f -> %>
    <div class="form-group form-text">
      <%= text_input f, :email, placeholder: "customer@company.com", class: "form-control form-control-margin", autofocus: true %>
    </div>
    <%= submit class: "btn btn-primary form-button" do %>
    <i class="fas fa-search"></i><span class="fas-in-button">Search</span>
    <% end %>
    <% end %>
  </div>
  <div class="main">
    <ul class="list-group">
      <%= for account <- @accounts do %>
      <li class="list-group-item">
        <div class="float-right">
          <small><%= link "become", to: Routes.admin_path(@conn, :become_account, account.id), class: "btn btn-danger btn-sm" %></small>

        </div>
        <div><%= account.email %></div>
        <div>
          <small class="source-details">Inserted at: <%= account.inserted_at %></small>
          <small class="source-details">Updated at: <%= account.updated_at %></small>
          <small class="source-details">Stripe customer:
            <%= if account.billing_account, do: link(account.billing_account.stripe_customer, to: "https://dashboard.stripe.com/customers/" <> account.billing_account.stripe_customer, style: "color: white;", target: "_blank") %></small>
        </div>
      </li>
      <% end %>
    </ul>
    <%= if @accounts.total_pages > 1 do %>
    <%= pagination_links @accounts, sort_by: @conn.params["sort_by"] %>
    <% end %>
  </div>
</div>

<script>
  document.addEventListener("DOMContentLoaded", async () => {
    await Dashboard.main()
  })

</script>
